/*
 * @Author: wangyingjie
 * @Date: 2021-08-18 15:14:01
 * @Email: wyj@hyrctec.com
 * @LastEditors: wangyingjie
 * @LastEditTime: 2021-08-25 10:27:07
 * @Company: hyrc
 * @FilePath: \TaskErrorManageApi\routes\projectProblemApi.js
 * @Description:
 */
var express = require('express')
var router = express.Router()

let { projectQuery, remarkinfoQuery, manageinfoQuery, UPDATEProject, add, deleted } = require("../database/Dao/ProjectProblem/projectProblem_dao") // 数据库操作
let result = require("../util/result.js") // 最终结果统一格式
/**
 * @api {get}  /projectApi/DeleteProject
 * @apiDescription 删除项目问题
 * @apiName Delete
 * @apiGroup User
 * @apiParam {string} id 项目问题标识
 * @apiSuccess {json} result
 * @apiSuccessExample {json} Success-Response:
 *  {
 *      "success" : "true",
 *      "data" :"删除成功"
 *  }
 * @apiSampleRequest http://localhost:3000/projectProblemApi/DeleteProject
 * @apiVersion 1.0.1
 */
router.get('/DeleteProject', function (req, res, next) {
  let urlParam = {
    ProjectId: req.query.ProjectId
  }
  console.log(urlParam)
  deleted(urlParam, function (success) {
    let r = result.createResult(success.affectedRows > 0 ? true : false, success.affectedRows > 0 ? "删除成功" : success.message)
    res.json(r)
  })
})
/**
 * @api {post} /projectApi/AddProject
 * @apiDescription 新增项目问题数据
 * @apiName Add
 * @apiGroup User
 * @apiParam {json} SendData
 * @apiSuccessExample {json} Success-Request:
 * {
 *   "Id":"",
 *   "ProjectId":"",
 *   "Follow":"",
 *   "State":"",
 *   "Priority":"",
 *   "Subject":""
 *   "AssigneUserID":"",
 *   "CreateUserID":"",
 *   "CreateDate":"",
 *   "UpdateDate":"",
 *   "BugCounts":"",
 *   "BadLevel":""
 *   "BreakDownRate":"",
 *   "StartTime":"",
 *   "EndTime":"",
 *   "OverProssece":"",
 *   "IsPublish":""
 * }
 * @apiSuccess {json} result
 * @apiSuccessExample {json} Success-Response:
 *  {
 *      "success" : "true",
 *       "data" : "添加成功"
 *  }
 * @apiSampleRequest http://localhost:3000/projectProblemApi/AddProject
 * @apiVersion 1.0.1
 */
router.post('/AddProject', function (req, res, next) {
  let urlParam = req.body
  console.log(urlParam)
  add(urlParam, function (success) {
    let r = result.createResult(success.affectedRows > 0 ? true : false, success.affectedRows > 0 ? "添加成功" : success.message)
    res.json(r)
  })
})
/**
 * @api {get} /projectApi/projectQuery
 * @apiDescription 查询项目详情
 * @apiName projectQuery
 * @apiGroup project
 * @apiParam {string} ProblemId
 * @apiSuccess {json} result
 * @apiSuccessExample {json} Success-Response:
 *  {
 *      "success" : "true",
 *      "data" :"结果数据"
 *  }
 * @apiSampleRequest http://localhost:3000/projectProblemApi/projectQuery
 * @apiVersion 1.0.1
 */
router.get('/projectQuery', function (req, res, next) {
  let urlParam = {
    ProblemId: req.query.ProblemId
  }
  console.log(urlParam)
  projectQuery(urlParam, function (success) {
    let r = result.createResult(true, success)
    res.json(r)
  })
})
/**
 * @api {get} /projectApi/remarkinfoQuery
 * @apiDescription 查询问题详情
 * @apiName remarkinfoQuery
 * @apiGroup project
 * @apiParam {string} ProblemId
 * @apiSuccess {json} result
 * @apiSuccessExample {json} Success-Response:
 *  {
 *      "success" : "true",
 *      "data" :"结果数据"
 *  }
 * @apiSampleRequest http://localhost:3000/projectProblemApi/remarkinfoQuery
 * @apiVersion 1.0.1
 */
router.get('/remarkinfoQuery', function (req, res, next) {
  let urlParam = {
    ProblemId: req.query.ProblemId
  }
  console.log(urlParam)
  remarkinfoQuery(urlParam, function (success) {
    let r = result.createResult(true, success)
    res.json(r)
  })
})
/**
 * @api {get} /projectApi/manageinfoQuery
 * @apiDescription 查询项目
 * @apiName manageinfoQuery
 * @apiGroup project
 * @apiParam {string} ProjectId
 * @apiSuccess {json} result
 * @apiSuccessExample 
 *  {
 *      "success" : "true",
 *      "data" :"结果数据"
 *  }
 * @apiSampleRequest http://localhost:3000/projectProblemApi/manageinfoQuery
 * @apiVersion 1.0.1
 */
router.get('/manageinfoQuery', function (req, res, next) {

  manageinfoQuery(function (success) {
    let r = result.createResult(true, success)
    res.json(r)
  })
})
/**
 * @api {post} /UsersApi/UPDATEProject
 * @apiDescription 修改项目详情数据
 * @apiName UPDATEProject
 * @apiGroup project
 * @apiParam {json} ProjectId
 * @apiSuccessExample {json} Success-Request:
 * {
 *      "success" : "true",
 *      "data" :"结果数据"
 * }
 * @apiSuccess {json} result
 * @apiSuccessExample {json} Success-Response:
 *  {
 *      "success" : "true",
 *       "data" : "修改成功"
 *  }
 * @apiSampleRequest http://localhost:3000/projectProblemApi/UPDATEProject
 * @apiVersion 1.0.1
 */
router.post('/UPDATEProject', function (req, res, next) {
  let urlParam = req.body
  console.log(urlParam)
  UPDATEProject(urlParam, function (success) {
    let r = result.createResult(success.affectedRows > 0 ? true : false, success.affectedRows > 0 ? "修改成功" : success.message)
    res.json(r)
  })
})
module.exports = router